package com.deepexi.sample.vo;


import lombok.Data;

@Data
public class Result<T> {

    public static final String SUCCESS_CODE = "200";

    public static final String FAIL_CODE = "400";

    private String code;

    private String msg;

    private T obj;

    public Result(String code, String msg, T obj) {
        this.code = code;
        this.msg = msg;
        this.obj = obj;
    }

    public static <T> Result success(T obj) {
        return new Result<T>(SUCCESS_CODE, "操作成功", obj);
    }

    public static <T> Result fail(String msg) {
        return new Result<T>(FAIL_CODE, msg, null);
    }

    public static <T> Result fail(String code, String msg) {
        return new Result<T>(code, msg, null);
    }

    public static boolean isSuccess(Result result) {
        if (result == null) {
            return false;
        }
        return SUCCESS_CODE.equals(result.getCode());
    }

    public boolean isSuccess() {
        return SUCCESS_CODE.equals(this.code);
    }

}
